<template>
  <div class="wrapper">
    <top></top>
    <div v-if="listData.length > 0" class="listWrapper">
      <div v-for="item of listData" :key="item.id" class="item" @click="viewDetail(item)">
        <div :class="['itemPic', calcIcon(item)]">
          <img v-if="item.iconUrl" style="width:100%;height:100%" :src="item.iconUrl" alt="背景图" />
        </div>
        <div class="name">
          <span class="ellipsis">{{ item.name }}</span>
        </div>
        <div class="des">
          <p class="ellipsis">{{ item.des }}</p>
        </div>
        <el-button @click="viewDetail(item)" size="medium" round>查看详情</el-button>
      </div>
    </div>
    <div class="noData" v-else>暂无数据</div>
    <div class="pagnationWrapper">
      <el-pagination
        style="text-align:center;"
        background
        layout="prev, pager, next"
        :total="pagnation.total"
        :page-size="pagnation.pageSize"
        :current-page.sync="pagnation.pageNum"
        @current-change="pageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import top from './components/top'
import { mapState, mapActions } from 'vuex'
import { encodeBase64 } from '../../utils/commonUtils'
export default {
  data() {
    return {
      bgClassMapping: {
        1: 'industry_app',
        2: 'mini_service',
        3: 'mdoel_manage'
      }
    }
  },
  components: {
    top
  },
  computed: {
    ...mapState({
      currentTab: (state) => state.home.currentTab || '1',
      queryKey: (state) => state.home.queryKey,
      listData: (state) => state.home.listData,
      pagnation: (state) => state.home.pagnation
    })
  },
  watch: {
    currentTab(newV) {
      this.$store.commit('home/setPagnation', { pageNum: 1 })
      this.$store.commit('home/setFilterId', {})
      this.getData()
    }
  },
  methods: {
    ...mapActions({
      pageChange: 'home/getList'
    }),
    calcIcon(data) {
      return !data.iconUrl && this.bgClassMapping[this.currentTab]
    },
    viewDetail(item) {
      // 暂时没有判断字段  临时使用
      this.$store.commit(
        'detail/setDetailType',
        item.reqParam === undefined ? 1 : 2
      )
      this.$router.push({ path: '/main/detail', query: { id: encodeBase64(item.id) } })
    },
    getData() {
      this.pageChange()
    }
  },
  created() {
    this.getData()
  }
}
</script>
<style lang="scss" scoped>
.wrapper {
  position: relative;
  width: 78vw;
  margin: 0 auto;
  .listWrapper {
    display: flex;
    flex-wrap: wrap;
    /*height: 72vh;*/
    .itemPic {
      width: 100%;
      height: 11vh;
      min-height: 100px;
      background-size: cover;
      &.industry_app {
        background: no-repeat center url('../../assets/industry_app.png');
      }
      &.mini_service {
        background: no-repeat center url('../../assets/mini_service.png');
      }
      &.mdoel_manage {
        background: no-repeat center url('../../assets/model_manage.png');
      }
    }
    .item {
      width: 15vw;
      /*height: 24vh;*/
      margin: 1.5%;
      padding: 1vw;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.1);
      border-radius: 8px;
      display: flex;
      flex-direction: column;
      align-items: center;
      cursor: pointer;
      .name {
        font-size: 18px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
        line-height: 3vh;
        height: 3vh;
        margin: 10px;
        .ellipsis {
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          display: inline-block;
          width: 15vw;
          text-align: center;
        }
      }
      .des {
        margin: 10px 0 ;
        width: 15vw;
        font-size: 15px;
        height: 8vh;
        text-align: center;
        .ellipsis {
          display: -webkit-box;
          -webkit-line-clamp: 3;
          margin: 0;
          color: rgba(111, 124, 130, 0.8);
          word-wrap: break-word;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }
      }
    }
  }
  .noData {
    height: 72vh;
    line-height: 50vh;
    text-align: center;
    color: #c1c1c1;
  }
}
</style>
